
# 双栈实现队列
class MyQueue {

    stack1;# 顺序栈
    stack2;# 逆序栈

    static new() {
        var queue = MyQueue();
        queue.stack1 = [];
        queue.stack2 = [];
        return queue;
    }

    push(x) {
        this.stack1.push(x);# 顺序插入栈顶
        this.stack2 = [];# 更新逆序栈
        for (var i = this.stack1.length()-1; i >= 0; i=i-1)
            this.stack2.push(this.stack1[i]);
    }

    pop() {
        var val = this.stack2.pop();# 移除逆序栈的栈顶
        this.stack1 = [];# 更新顺序栈
        for (var i = this.stack2.length()-1; i >= 0; i=i-1)
            this.stack1.push(this.stack2[i]);
        return val;
    }

    peek() {
        return this.stack2[this.stack2.length()-1];
    }

    empty() {
        return this.stack1.length() == 0;
    }
}

# 测试栈
var queue = MyQueue.new();
queue.push(123);
print(queue.peek());
print(queue.empty());
print(queue.pop());